<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Menu_widget extends MY_Widget {
	function __construct(){
		parent::__construct();
	}

	function run(){
		if($HTML = $this->cache->get("menu_widget_html")){
			return $HTML;
		}

		$this->load->model('category_model','categoryModel');
	 	$result = $this->categoryModel->get(array("order"=>"sort ASC"));
	 	$categories = array();
	 	if(!empty($result)){
	 		foreach ($result as $key => $value) {
		    $categories['items'][$value['id']] = $value;
		    $categories['parents'][$value['parent_id']][] = $value['id'];
		 	}
	 	}
	 	$this->_assign('categories',$categories);
		
		$HTML = $this->_fetch("menu");
		$this->cache->write($HTML,"menu_widget_html",(3600*24));
		return $HTML;
	}
}